﻿using System;

using ApplicationLibrary;
using ApplicationLibrary.SqlConnector;

namespace Vintner.Items.ModuleData
{
    internal class RegisterModule : ApplicationLibrary.SqlConnector.RegisterModule
    {
        public override string Application()
        {
            return "VINT";
        }

        public override string Module()
        {
            return "ITEM";
        }

        public override int CurrentVersion()
        {
            return 1;
        }

        public override Version DllVersion
        {
            get
            {
                return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            }
        }

        public override void RegisterCountersAndCodes()
        {
            GlobalInfo.AddCodeType("Items", Properties.Resources.CN_Items);
        }

        public override void AddScrounger(ApplicationLibrary.DBManager.iScrounger frm, NameSpace nameSpace)
        {
            if (nameSpace.ApplicationPath == "Vintner.Masters.Forms.Customers" ||
                nameSpace.ApplicationPath == "Vintner.Masters.Library.CustomersCreator")
                frm.ScroungerList.Add(new Vintner.Items.Scrounger.MasterScrounger(frm));
        }

        public override ApplicationLibrary.Preferences.PreferencePanel[] RegisterPreferences()
        {
            //return new ApplicationLibrary.Preferences.PreferencePanel[]
            //{
            //    new AccountingPreferencePanel()
            //};
            return null;
        }

        protected override bool CreateDBTables()
        {
            SqlCreateTable newTable = new SqlCreateTable(SqlABConnection);

            #region VI_Items

            if (SearchTable(VI_Items.Name))
            {
                newTable.NewTable(VI_Items.Name);

                newTable.AddColumn(VI_Items.Item);
                newTable.AddColumn(VI_Items.Description);
                newTable.AddColumn(VI_Items.Size);
                newTable.AddColumn(VI_Items.Disabled);

                newTable.AddPrimaryKey(VI_Items.Item);

                newTable.Create();
            }

            #endregion

            #region VI_ItemsPrice

            if (SearchTable(VI_ItemsPrice.Name))
            {
                newTable.NewTable(VI_ItemsPrice.Name);

                newTable.AddColumn(VI_ItemsPrice.Item);
                newTable.AddColumn(VI_ItemsPrice.Category);
                newTable.AddColumn(VI_ItemsPrice.Price);
                newTable.AddColumn(VI_ItemsPrice.TaxCode);
                newTable.AddColumn(VI_ItemsPrice.Disabled);

                newTable.AddPrimaryKey(new iColumn[] { VI_ItemsPrice.Item, VI_ItemsPrice.Category });

                newTable.Create();
            }

            #endregion

            #region VI_ItemCustomerPrice

            if (SearchTable(VI_ItemCustomerPrice.Name))
            {
                newTable.NewTable(VI_ItemCustomerPrice.Name);

                newTable.AddColumn(VI_ItemCustomerPrice.Item);
                newTable.AddColumn(VI_ItemCustomerPrice.Customer);
                newTable.AddColumn(VI_ItemCustomerPrice.Category);
                newTable.AddColumn(VI_ItemCustomerPrice.Disabled);

                newTable.AddPrimaryKey(new iColumn[] { VI_ItemCustomerPrice.Item, VI_ItemCustomerPrice.Customer, VI_ItemCustomerPrice.Category });

                newTable.Create();
            }

            #endregion

            return true;
        }

        protected override bool UpdateDBTables()
        {
            return true;
        }
    }
}